if lib and not lib.tostring then


function lib:tostring(param, indent)
	if type(param) == "number" then
		return tostring(param)
	elseif type(param) == "string" then
		return string.format("%q", param)
	elseif type(param) == "boolean" then
		return tostring(param)
	elseif type(param) == "nil" then
		return tostring(nil)
	elseif type(param) == "table"
		and (not indent
			or indent >= 0
		)
	then
		local tab, str, s
		if indent then
			tab = string.rep("\t", indent)
		else
			tab = ""
		end
		str = "{\n"
		for k, v in pairs(param) do
			if indent == false then
				s = lib:tostring(v, -1)
			else
				s = lib:tostring(v, int(indent) + 1)
			end
			if type(k) == "string" then
				if string.match(k, "%s") then
					s = tab .. "  [\"" .. k .. "\"] = " .. s .. ",\n"
				else
					s = tab .. "  " .. k .. " = " .. s .. ",\n"
				end
			elseif type(k) == "number" then
				s = tab .. "  [" .. k .. "] = " .. s .. ",\n"
			else
				s = tab .. "  --[[ " .. string.gsub(tostring(k) .. " = " .. s, "\n", "\t") .. " ]]\n"
			end
			str = str .. s
		end
		return str .. tab .. "}"
	end
	return tostring(nil) .. " --[[ " .. tostring(param) .. " ]] "
end


function lib:toline(param)
	return string.gsub(lib:tostring(param), "\n%s*", "")
end


function split(str, sep)
	str = tostring(str)
	if not sep or #sep < 1 then
		sep = "%s"
	end
	str = string.gsub(str, sep, "\000")
	sep = "\000"
	local t = {}
	local b, e, s
	local p = 1
	repeat
		b, e, s  = string.find(str, "([^" .. sep .. "]*)" .. sep, p)
		if b then
			table.insert(t, s)
			p = e + 1
		end
	until not b
	if p == 1 then
		table.insert(t, str)
	elseif p <= #str then
		table.insert(t, string.sub(str, p, #str))
	else
		table.insert(t, "")
	end
	return t
end


function lib:LoadString(ini, def)
	def = def or {}
	if type(ini) == "string" then
		local str = string.gsub(ini, "^%s+", "")
		str = string.gsub(str, "%s+$", "")
		if not string.match(str, "^[{].*[}]$") then
			str = "{" .. str .. "}"
		end
		str = "return " .. str
		ini = load(str)
		if ini then
			ini = ini()
		else
			fail("LoadString failed: " .. str)
		end
	end
	return self:clone(ini, def)
end


end -- of file
